package library.operation;

import library.book.BookList;

import java.util.Scanner;

public class DelOpretation implements Opretation{
    public void work(BookList bookList) {
        System.out.println("删除图书");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int flg=-1;
        int pos=0;
        for (int i = 0; i < bookList.getBooksize(); i++) {
            if(name.equals(bookList.getbooks()[i].getName())) {
                flg=1;
                pos=i;
                break;
            }
        }
        if(flg==1){
            for (int i = pos; i < bookList.getBooksize()-1; i++) {
                bookList.getbooks()[i]=bookList.getbooks()[i+1];
            }
            bookList.setBooksize(bookList.getBooksize()-1);
            System.out.println("删除成功");
        }else {
            System.out.println("要删除的图书不存在");
        }
    }
}
